import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicArrowButton;
import java.awt.*;
import java.util.ArrayList;

public class MyLibrary extends JPanel{
    static Dominoes SelectedDominoes = null;
    int DominoCount = 7;
    public  static MyLibrary Instance = new MyLibrary();
    ArrayList<Dominoes> AllMyDominoes = new ArrayList<>();
    FlowLayout f = new FlowLayout(FlowLayout.CENTER);
    public void Init(){
        DominoCount = 28;
       // Border blackLine = BorderFactory.createLineBorder(Color.BLACK);
        //Instance.setSize(800,200);
        WidthUpdate();
        Instance.setVisible(true);
      //  Instance.setBorder(blackLine);
        //GridLayout gridLayout = new GridLayout();
        f.setHgap(26);
        f.setVgap(30);
        Instance.setLayout(f);
        for(int i = 0;i < DominoCount;i++){
            Dominoes tmp = DominoManager.Instance.GetADomino();
            tmp.addMouseListener(tmp);
            AllMyDominoes.add(tmp);
            this.add(tmp);
        }
    }
    public void WidthUpdate(){
        int width = DominoCount * 75 + (DominoCount-1)*46;
        Instance.setSize(width,200);
    }
    public void RemoveMyDominoes(){
        remove(SelectedDominoes);
        SelectedDominoes = null;
    }
    public void AllDomiDown(){
        for (Dominoes tmp :AllMyDominoes){
            tmp.isClicked = false;
            int preX = tmp.getX();
            tmp.setLocation(preX,30);
        }
        SelectedDominoes = null;
    }
    public void Update(){
        DominoCount--;
        WidthUpdate();
        AllMyDominoes.remove(SelectedDominoes);
        remove(SelectedDominoes);
        SelectedDominoes = null;
        repaint();
    }
}
